Skip to content

Add option group support for help output#7

Merged
evanphx merged 1 commit into
mainfrom
evan/option-groups
Feb 11, 2026
Merged

Add option group support for help output#7
evanphx merged 1 commit into
mainfrom
evan/option-groups

Conversation

@evanphx

@evanphx evanphx commented Feb 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Flags can now be organized under named group headings (e.g., "Global Options:") in help output via three mechanisms with clear precedence:
    1. InGroup() option on FromStruct call (highest)
    2. group:"..." tag on embedded struct field
    3. _ struct{} group:"..."`` self-declaration inside a struct
  • Adds FlagSet.Group() method for programmatic (non-struct) grouping
  • Extracts shared flag rendering into WriteFlagHelp(), eliminating duplication between ShowHelp() and dispatcher.showCommandHelp()

Test plan

  • All existing tests pass (no regressions)
  • TestFromStructSelfDeclaredGroup_ struct{} assigns group to all flags
  • TestFromStructWithGroupInGroup() assigns group to all flags
  • TestFromStructEmbeddedGroupTaggroup tag on embedded struct assigns group
  • TestGroupPrecedenceInGroup() > embedded tag > self-declaration
  • TestGroupHelpOutput — named groups render before default "Options:"
  • TestGroupBackwardCompatibility — no groups = single "Options:" heading
  • TestGroupMethodProgrammaticGroup() API works for non-struct usage
  • TestGroupOrderPreserved — groups appear in insertion order, not alphabetical
  • TestShowHelpWithGroups — full ShowHelp() integration with groups

Flags can now be organized under named group headings (e.g., "Global
Options:") via three mechanisms with clear precedence:

1. InGroup() option on FromStruct call (highest)
2. `group:"..."` tag on embedded struct field
3. `_ struct{} \`group:"..."\`` self-declaration inside a struct

Also adds FlagSet.Group() for programmatic use and extracts shared flag
rendering into WriteFlagHelp() to eliminate duplication between ShowHelp
and dispatcher.showCommandHelp.
@evanphx evanphx requested a review from a team as a code owner February 11, 2026 22:16
@evanphx evanphx merged commit 4aada85 into main Feb 11, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants